package rolesystem.agentlogic.utilityclasses;

import java.util.ArrayList;


public class AgentMap
{
	private static ArrayList<AgentData> agentList;
	
	
	static
	{
		agentList= new ArrayList<AgentData>();	
	}
	
	public static void updateAgent(AgentData updatedAgent) 
	{
		boolean agentfound=false; 
		
		for(int i=0;i<agentList.size();i++)
		{
			if(agentList.get(i).id==updatedAgent.id)
			{
				agentfound=true;
				agentList.set(i,updatedAgent);		
				break;
			}
		}  
		
		if(agentfound==false)
		{
			agentList.add(updatedAgent); 
		}  
		
	}
	
	public static int getSize() 
	{
		return agentList.size();	
	}
	
	public static PositionSq getPositionByIndex(int index) 
	{
		return agentList.get(index).position_agent;	
	}
	
	public static int getIdByIndex(int index) 
	{
		return agentList.get(index).id;	
	}
	
	public synchronized static boolean isAgentHere(PositionSq position) 
	{	
		for(int i=0;i<agentList.size();i++)
		{
			if(agentList.get(i).position_agent.equalTo(position))
			{
				return true;
			}
		}  
		
		return false;
	}
	
	
}
